<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>领取娃娃币</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        @font-face {
            font-family: '华康海报';
            src: url('font/华康海报体.ttf');
        }
        .box{
            width: 10rem;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items:center;
            font-size: 0;
        }
        .wrapper{
            width: 10rem;
            position: relative;
        }
        .box:before{
            position: absolute;
            top: 0;
            left: 0;
            z-index: -1;
            content: '';
            width: 10rem;
            height: 50%;
            background-color: #bbf0ff;
        }
        .box:after{
            position: absolute;
            bottom: 0;
            left: 0;
            z-index: -1;
            content: '';
            width: 10rem;
            height: 50%;
            background-color: #e4e4e4;
        }

        .title{
            font-family: '华康海报';
            width: 8rem;
            text-align: center;
            position: absolute;
            top: 2.2rem;
            left: 1rem;
            font-size: 0.8rem;
            color: deeppink;
            line-height: 1rem;
        }

        .advertising{
            width: 6rem;
            height: 4rem;
            position: absolute;
            right: 0.2rem;
            top: 6.5rem;
        }
        .advertising .ad{
            width: 100%;
            height: 100%;
            background-color: #FFFFFF;
        }

        .qrWrapper{
            display: none;
            width: 5rem;
            height: 5rem;
            position: absolute;
            right: 1rem;
            bottom: 1rem;
        }
        .qrWrapper .qr{
            width: 3rem;
            height: 3rem;
            margin: 0 auto;
        }
        .qrWrapper .text{
            margin-top: 0.2rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            line-height: 0.65rem;
            font-size: 0.5rem;
            color: #3e3e3e;
        }

        .codeWrapper{
            display: none;
            position: absolute;
            /*right: 1rem;*/
            /*bottom: 2rem;*/
            right: 10px;
            bottom: 20vh;
            font-size: 20px;
            text-align: center;
            /*width: 4rem;*/
            width: 6rem;
            height: 1rem;
        }
        .codeWrapper .loadBtn{
            font-size: 22px;
            color: #ffffff;
            background-color: #f74985;
            width: 3rem;
            height: 1rem;
            line-height: 1rem;
            border-radius: 0.5rem;
            /*margin-left: 0.5rem;*/
            margin-top: 10px;
        }
        .flex{
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
        }
    </style>
    <script type="text/javascript" src="js/rem.js"></script>
</head>
<body>
<div class="box">
    <div class="wrapper">
        <div class="title">
            <h3 id="nickName" style="height: 1rem;line-height: 1rem;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"></h3>
            <p>送给你<span style="font-family: 微软雅黑">50</span>个币</p>
            <p>邀请你一起抓娃娃</p>
        </div>
        <div class="advertising">
            <p class="ad" style="background: url('images/wxQr2_bubble.png') 100% 100% no-repeat;background-size: 100% 100%;"></p>
        </div>
        <div class="qrWrapper">
            <div class="qr"></div>
            <div class="text">
                <p>长按二维码</p>
                <p>下载呆萌抓娃娃</p>
            </div>
        </div>
        <div class="codeWrapper">
            <p class="yqCode">
                领币邀请码
                <span id="code"></span>
            </p>
            <p class="loadBtn" id="load">立即下载</p>
        </div>
        <img src="images/wxQr2_bgi.png" alt="" style="width: 100%;">
    </div>
</div>
<script type="text/javascript" src="js/zepto.min.js"></script>
<script type="text/javascript">
    var img = new Image();
    img.style.width = '100%';
    img.style.height = '100%';
    $(function () {
        // get userName
        $.ajax({
            url:'http://api.yanyuan01.cn/v1/user_base/get_qrcode?uid='+getU(),
            type:"GET",
            success:function (data) {
                if(data.status === 'ERROR'){
                    if(operator()==='wexin'){
                        $('.qrWrapper').show().children('.qr').html('<p style="font-size: 0.5rem;text-align: center;padding-top: 1rem;color: #000000;font-family: monospace;">数据加载失败</p>');
                    }else{
                        $('.codeWrapper').addClass('flex').children('.yqCode').html('邀请码加载失败')
                    }
                    return;
                }
                if(data.status === 'OK'){
                    $('#nickName').html(data.res.NickName);
                    if(operator()==='wexin'){
                        $('.qrWrapper').show();
                        img.src = data.res.QrcodeUrl;
                        img.onload = function () {
                            $('.qr').empty().append(img);
                            $('.text').html('<p>长按二维码</p><p>下载呆萌抓娃娃</p>');
                        }
                    }else{
                        $('.codeWrapper').addClass('flex');
                        if(operator()==='android'){
                            $('#code').text(data.res.Id);
                        }
                        if(operator()==='iphone'){
                            $('.yqCode').hide();
                        }
                    }
                }
                $('#load').click(function () {
                    if(operator()==='iphone'){
                        window.location.href = 'http://tg.dmwawa.com/limit_act.html?i=20012'
                    }else{
                        window.location.href = 'http://file.yanyuan01.cn/apk/140.apk'
                    }
                })
            },
            fail:function (err) {
                console.log(err)
            }
        })
    });

    function getU() {
        // getCode
        if(window.location.href && window.location.href.split('?')[1]){
            opt=window.location.href.split('?')[1];
            argsArr = opt.split('&');
            for (var i=0; i<argsArr.length; i++) {

                if (argsArr[i].split('=')[0] === 'yq_code') {
                    return yqCode = argsArr[i].split('=')[1];
                } else if (argsArr[i].split('=')[0] === 'from') {
                    fromMsg = argsArr[i].split('=')[1];
                } else if (argsArr[i].split('=')[0] === 'isappinstalled') {
                    installMsg = argsArr[i].split('=')[1];
                } else {
                    return;
                }

            }
        }else{
            return;
        }
    }

    function operator() {
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        var isWeiXin = u.toLowerCase().indexOf('micromessenger') !== -1; // 微信终端

        if (isWeiXin) return 'wexin';
        if (isiOS) return 'iphone';
        if (isAndroid) return 'android';
    }

</script>
</body>
</html>